package com.atguigu.dga.dolphinscheduler.mapper;

import com.atguigu.dga.dolphinscheduler.bean.TDsTaskInstance;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tubage
 * @since 2024-03-19
 */
@Mapper
@DS("dolphinscheduler")
public interface TDsTaskInstanceMapper extends BaseMapper<TDsTaskInstance> {
    @Select("select\n" +
            "    t1.*\n" +
            "    from t_ds_task_instance t1\n" +
            "join\n" +
            "(select\n" +
            "    name,\n" +
            "    max(id) max_id\n" +
            "    from t_ds_task_instance\n" +
            "where state = 7 and date_format(start_time, '%Y-%m-%d') = #{assessDate}\n" +
            "group by name) t2\n" +
            "on t1.id = t2.max_id")
    List<TDsTaskInstance> selectTdsTaskIntanceList(String assessDate);

}
